﻿@inherits UmbracoTemplatePage
@{
    // Model.Content is the current page that we're on
    // AncestorsOrSelf is all of the ancestors this page has in the tree
    // (1) means: go up to level 1 and stop looking for more ancestors when you get there
    // First() gets the first ancestor found (the home page, on level 1)
    var homePage = CurrentPage.AncestorsOrSelf(1).First();
}

<!-- Contact -->
<section>
    <h2 class="major"><span>Get in touch</span></h2>
    <ul class="contact">
        @RenderLinkIfNotEmpty(homePage.FacebookLink, "facebook", "Facebook")
        @RenderLinkIfNotEmpty(homePage.TwitterLink, "twitter", "Twitter")
        @RenderLinkIfNotEmpty(homePage.RssLink, "rss", "RSS")
        @RenderLinkIfNotEmpty(homePage.DribbbleLink, "dribbble", "Dribbble")
        @RenderLinkIfNotEmpty(homePage.LinkedinLink, "linkedin", "Linked In")
        @RenderLinkIfNotEmpty(homePage.GoogleLink, "googleplus", "Google+")
    </ul>
</section>
<!-- /Contact -->

@helper RenderLinkIfNotEmpty(dynamic link, string cssClass, string linkName)
{
    // A helper function is handy when you have to do the same thing over and over again
    // So now we only have to write the "if" check and list item once, and we only need
    // to put in the things that can vary
    
    if (string.IsNullOrEmpty(link) == false)
    {
        <li><a href="@link" class="@cssClass">@linkName</a></li>
    }
}